package com.ipc.app.util.converter;

import java.util.LinkedList;
import java.util.List;

import com.ipc.app.dal.doObject.AddressDO;
import com.ipc.app.dal.doObject.InformationDO;
import com.ipc.app.model.Address;
import com.ipc.app.model.Car;
import com.ipc.app.model.Information;

/**
 * @author haijie.zhang
 * 
 */
public class InformationConverter {

	public static Information informationDOToCore(InformationDO informationDO,
			List<AddressDO> addressDOs) {
		if (null == informationDO) {
			return null;
		}
		Information information = new Information();
		information.setCreateTime(informationDO.getCreateTime());

		information.setDepartureTime(informationDO.getDepartureTime());

		information.setInformationId(informationDO.getInformationId());
		information.setMemo(informationDO.getMemo());
		information.setModifyTime(informationDO.getModifyTime());
		information.setPrice(informationDO.getPrice());
		information.setSeatNumber(informationDO.getSeatNumber());
		information.setUserId(informationDO.getUserId());
		information.setBookedSeatNumber(informationDO.getBookedSeatNumber());
		information.setType(informationDO.getType());
		information.setStatus(informationDO.getStatus());

		Car car = new Car();
		car.setCarId(informationDO.getCarId());
		information.setCar(car);

		if (null != addressDOs && addressDOs.size() > 0) {
			List<Address> addresses = new LinkedList<Address>();
			for (AddressDO addressDO : addressDOs) {
				Address address = AddressConverter.addressDOToCore(addressDO);
				addresses.add(address);
			}
			information.setAddresses(addresses);
		}
		return information;
	}

	public static InformationDO informationCoreToDO(Information information) {
		InformationDO informationDO = new InformationDO();

		informationDO.setInformationId(information.getInformationId());
		informationDO.setMemo(information.getMemo());
		informationDO.setPrice(information.getPrice());
		informationDO.setSeatNumber(information.getSeatNumber());
		informationDO.setUserId(information.getUserId());
		informationDO.setDepartureTime(information.getDepartureTime());
		Car car = information.getCar();
		if (null != car) {
			informationDO.setCarId(car.getCarId());
		}
		informationDO.setBookedSeatNumber(information.getBookedSeatNumber());
		informationDO.setType(information.getType());
		informationDO.setStatus(information.getStatus());

		return informationDO;

	}
}
